package rd.system.toeicbridge 
{
	import com.greensock.TweenLite;
	import com.sff.site.core.INode;
	import com.sff.system.ModuleSystem;
	import flash.display.Bitmap;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.geom.ColorTransform;
	import flash.text.TextField;
	
	/**
	 * ...
	 * @author 
	 */
	public class MenuItem extends Sprite {
		
		public var mcBG:MovieClip;
		public var txtLabel:TextField;
		
		private var node:INode;
		
		public function MenuItem() {
				
			this.buttonMode = true;
			this.mouseChildren = false;
			this.addEventListener(MouseEvent.CLICK, onClickHandler);
			
			this.addEventListener(MouseEvent.MOUSE_OVER, onOverHandler);
			this.addEventListener(MouseEvent.MOUSE_OUT, onOutHandler);
		}
		
		private function onOverHandler(evt:MouseEvent):void {
			TweenLite.to(mcBG, 0.5, { alpha: 0.75 } );
		}
		
		private function onOutHandler(evt:MouseEvent):void {
			TweenLite.to(mcBG, 0.3, { alpha: 0.35 } );
		}
		
		private function onClickHandler(evt:MouseEvent):void {
			if (node) {
				node.activate();
			}
		}
		
		public function setData(system:ModuleSystem, xml:XML):void {
			
			txtLabel.htmlText = xml.label.toString();
			system.styleManager.applyStyle(txtLabel, 'menuItemStyle');
			txtLabel.x = 5 + 72 + 5;
			txtLabel.y = mcBG.height / 2 - txtLabel.textHeight / 2 - 2;
			
			var color:ColorTransform = new ColorTransform();
			color.color = uint(xml.color.toString());
			mcBG.transform.colorTransform = color;
			mcBG.alpha = 0.35;
			
			node = system.siteManager.getChild(xml.@nodeid.toString());
		}
		
		public function addImage(bmp:Bitmap):void {
			bmp.width = 72;
			bmp.scaleY = bmp.scaleX;
			
			bmp.x = 5;
			bmp.y = mcBG.height / 2 - bmp.height / 2;
			
			addChild(bmp);
		}		
	}
}